﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.Odbc;

namespace CSM.Views.Content
{
    public partial class Test1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string filepath = Server.MapPath("test2.csv");

  if (!File.Exists(filepath))

  {

  Page.RegisterClientScriptBlock("msg", "<script>alert('该文件不存在！')</script>");

  }

  else

  {

  string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=";

  strConn += ";Extensions=asc,csv,tab,txt;";

  OdbcConnection objConn = new OdbcConnection(strConn);

  DataSet ds = new DataSet();

  try

  {

  string strSql = "select * from " + filepath;

  OdbcDataAdapter odbcCSVDataAdapter = new OdbcDataAdapter(strSql, objConn);

  odbcCSVDataAdapter.Fill(ds);

  this.GridView2.DataSource = ds.Tables[0];

  this.GridView2.DataBind();

  }

  catch (Exception ex)

  {

  throw ex;

  }

  }

  }

    }
}
